package com.yisu.expressway.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.yisu.expressway.R;
import com.yisu.expressway.model.ServiceDistrictObj;
import com.yisu.expressway.settings.AppConstant;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/10/5 0005.
 */

public class ServiceListAdapter extends RecyclerView.Adapter<ServiceListAdapter.ServiceViewHolder>  {


    ArrayList<ServiceDistrictObj.AvailableServiceObj> mData = new ArrayList<>();
    private Context mContext;

    public ServiceListAdapter (Context context){
        this.mContext = context;
    }

    public void setData(ArrayList<ServiceDistrictObj.AvailableServiceObj> list){
        this.mData = list;
        notifyDataSetChanged();
    }

    @Override
    public ServiceViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View mView = LayoutInflater.from(mContext).inflate(R.layout.service_info_item, parent, false);
        return new ServiceListAdapter.ServiceViewHolder(mView);
    }

    @Override
    public void onBindViewHolder(ServiceViewHolder holder, int position) {
        if(mData.size() <= position ){
            return;
        }

        ServiceDistrictObj.AvailableServiceObj item = mData.get(position);
        int imgId = -1;
        switch (item.itemType){
            case AppConstant.TYPE_CAR_PARK:
                imgId = R.drawable.ic_car_park;
                break;
            case AppConstant.TYPE_CAR_SERVICE:
                imgId = R.drawable.ic_car_service;
                break;
            case AppConstant.TYPE_FASTFOOD:
                imgId = R.drawable.ic_fastfood;
                break;
            case AppConstant.TYPE_RESTRAUNT:
                imgId = R.drawable.ic_restaurant;
                break;
            default:
                break;
        }

        if(imgId != -1){
            holder.mIv_icon.setImageResource(imgId);
        }
        holder.mTv_name.setText(item.itemName);
        holder.mTv_des.setText(item.itemDesc);

    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    class ServiceViewHolder extends RecyclerView.ViewHolder {

        @Bind(R.id.iv_icon) ImageView mIv_icon;
        @Bind(R.id.tv_name) TextView mTv_name;
        @Bind(R.id.tv_des) TextView mTv_des;

        public ServiceViewHolder(View itemView){
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
